/**
 * 
 */
package com.kth.subtranslator.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;

import com.kth.subtranslator.ITranslateDriver;
import com.kth.subtranslator.ITranslateDriverConfiguration;
import com.kth.subtranslator.ui.controller.SrtPanelController;

/**
 * @author Kevin Thackray
 *
 */
public class DriverConfigurationDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private final SrtPanelController srtController;
	private final ConfigurationPanel configurationPanel = new ConfigurationPanel();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			DriverConfigurationDialog dialog = new DriverConfigurationDialog(null);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public DriverConfigurationDialog(SrtPanelController srtController) {
		this.srtController = srtController;
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
//		contentPanel.setLayout(new FlowLayout());
//		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
//		contentPanel.add(configurationPanel);
		getContentPane().add(configurationPanel, BorderLayout.CENTER);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				okButton.addActionListener( new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						setVisible(false);
					}
				});
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				cancelButton.addActionListener( new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						setVisible(false);
					}
				});
				buttonPane.add(cancelButton);
			}
		}
		{
			final JComboBox comboBox = new JComboBox();
			comboBox.setRenderer( new DriverRenderer() );
			for (ITranslateDriver d :  srtController.getDrivers()) {
				comboBox.addItem(d);
			}
			comboBox.addActionListener( new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					ITranslateDriver selectedDriver = (ITranslateDriver) comboBox.getSelectedItem();
					configurationPanel.setConfiguration(selectedDriver.getConfiguration());
				}
			});
			getContentPane().add(comboBox, BorderLayout.NORTH);
		}
	}

}
